package com.example.demo.main.rabbitmq.exchange.topic;

import com.example.demo.main.rabbitmq.utils.RabbitmqConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class Producer4TopicExchange {


    public static void main(String[] args) throws Exception {


        Connection connection = RabbitmqConnectionUtil.getConnection();
        //3 创建Channel
        Channel channel = connection.createChannel();
        //4 声明
        String exchangeName = "test_topic_exchange";
        String routingKey1 = "user.save";
        String msg1 = "Hello World RabbitMQ 4 Topic Exchange Message ...routingKey=" + routingKey1;
        String routingKey2 = "user.update";
        String msg2 = "Hello World RabbitMQ 4 Topic Exchange Message ...routingKey=" + routingKey2;
        String routingKey3 = "user.delete.abc";
        String msg3 = "Hello World RabbitMQ 4 Topic Exchange Message ...routingKey=" + routingKey3;

        //5 发送
        channel.basicPublish(exchangeName, routingKey1, null, msg1.getBytes());
        channel.basicPublish(exchangeName, routingKey2, null, msg2.getBytes());
        channel.basicPublish(exchangeName, routingKey3, null, msg3.getBytes());
        channel.close();
        connection.close();
    }

}
